<?php
$dataProvider=new CArrayDataProvider($model->buyMoreProducts, array(
    'pagination'=>array(
        'pageSize'=>10
    )
));

$this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'buy-more-list',
        'dataProvider'=>$dataProvider,
        'columns'=>array(
            array(
                'header'=>'',
                'value'=>'$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)'
            ),
            array(
                'name' => 'avatar',
                'value' => '"<img src=\"".($data->avatar?Yii::app()->baseUrl."/".$data->avatar->url:"")."\" width=\"50\" height=\"50\"/>"',
                'type' => 'raw',
                'filter' => FALSE,
                'sortable' => FALSE,
            ),
            array(
                'name'=>'code',                
            ),
            array(
                'name'=>'name'
            ),
            array(
                'name'=>'quantity'
            ),
            array(
                'class'=>'CButtonColumn',
                'template'=>'{delete}',
                'deleteButtonUrl'=>'Yii::app()->createUrl("admin/product/deleteProductPlus", array("masterId"=>'.$model->id.', "buyMoreId"=>$data->id))'
            )
        ),
        'htmlOptions'=>array(
            'style'=>'width:640px; display:inline-block'
        )
));
?>

<div class="button" style="margin-left: 110px">
    <?php echo CHtml::button(Yii::t('main', 'Add product buy more'), array('id'=>'btn-add-buymore')) ?>
</div>

<script type="text/javascript">
    $(function(){
        var buymorePopupWindow=null;
        $('#btn-add-buymore').click(function(){
            buymorePopupWindow=window.open('<?php echo Yii::app()->createUrl('admin/product/addProductPlus', array('masterId'=>$model->id, 'plusType'=>  ProductPlus::TYPE_BUY_MORE)) ?>/listId/buy-more-list', 'productplus', "height=440,width=630");
            if(buymorePopupWindow.opener===null){
                buymorePopupWindow.opener=window;
            }
        });
    });
</script>
